# Maintainer: Felix Yan <felixonmars@archlinux.org>

_hkgname=microlens-mtl
pkgname=haskell-microlens-mtl
pkgver=0.2.0.3
pkgrel=1
pkgdesc="microlens support for Reader/Writer/State from mtl"
url="https://github.com/monadfix/microlens"
license=('BSD')
arch=('loong64' 'x86_64')
depends=('ghc-libs' 'haskell-microlens' 'haskell-transformers-compat')
makedepends=('ghc')
source=("https://hackage.haskell.org/packages/archive/${_hkgname}/${pkgver}/${_hkgname}-${pkgver}.tar.gz")
sha512sums=('b8fee6a3ae6ecae28b2564566063d26cd048cef525dbfdbb63913d32197fdbb07d23608c37b0863a08794978066876c350b996282ce0c2df6731006221ef0fc1')

build() {
    cd $_hkgname-$pkgver

    runhaskell Setup configure -O --enable-shared --enable-executable-dynamic --disable-library-vanilla \
        --prefix=/usr --docdir=/usr/share/doc/$pkgname --datasubdir=$pkgname \
        --dynlibdir=/usr/lib --libsubdir=\$compiler/site-local/\$pkgid --ghc-option=-fllvm
    runhaskell Setup build $MAKEFLAGS
    runhaskell Setup register --gen-script
    runhaskell Setup unregister --gen-script
    sed -i -r -e "s|ghc-pkg.*update[^ ]* |&'--force' |" register.sh
    sed -i -r -e "s|ghc-pkg.*unregister[^ ]* |&'--force' |" unregister.sh
}

package() {
    cd $_hkgname-$pkgver

    install -D -m744 register.sh "$pkgdir"/usr/share/haskell/register/$pkgname.sh
    install -D -m744 unregister.sh "$pkgdir"/usr/share/haskell/unregister/$pkgname.sh
    runhaskell Setup copy --destdir="$pkgdir"
    install -D -m644 LICENSE "$pkgdir"/usr/share/licenses/$pkgname/LICENSE
    rm -f "$pkgdir"/usr/share/doc/$pkgname/LICENSE
}
